package com.fanfanwang.ffw.app.adapter;

import java.util.ArrayList;
import java.util.concurrent.TimeUnit;

import com.fanfanwang.ffw.app.AppConstant;
import com.fanfanwang.ffw.app.asynctask.GetMsgListAsyncTask;
import com.fanfanwang.ffw.app.bean.GlyMessageBean;
import com.fanfanwang.ffw.app.bean.MsgListBean;
import com.fanfanwang.ffw.app.bean.SectionBean;
import com.fanfanwang.ffw.app.bean.ServiceBean;
import com.fanfanwang.ffw.app.bean.ServiceCarWashBean;
import com.fanfanwang.ffw.app.tenant.R;
import com.fanfanwang.ffw.app.tools.TimeUtils;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;


public class GlyMessageListAdapter extends BaseAdapter {

	private ArrayList<MsgListBean> beans=new ArrayList<MsgListBean>();
	private Context mContext;
	public GlyMessageListAdapter(Context mContext,ArrayList<MsgListBean> beans) {
		// TODO Auto-generated constructor stub
		this.mContext = mContext;
		this.beans.clear();
		this.beans.addAll(beans);
	}
	public void addList(ArrayList<MsgListBean> beans){
		this.beans.addAll(beans);
	}
	public void resetData(ArrayList<MsgListBean> beans){
		this.beans=beans;
	}
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return beans.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		final ViewHolder holder;
		if (convertView == null) {
			LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			convertView = inflater.inflate(R.layout.item_for_messagelist, null);
			holder = new ViewHolder();
			holder.num = (TextView) convertView.findViewById(R.id.num);
			holder.addtime = (TextView) convertView.findViewById(R.id.yuyue_date);
			holder.nick = (TextView) convertView.findViewById(R.id.mess_nick_value);
			holder.car_num = (TextView) convertView.findViewById(R.id.mess_car_num_value);
			holder.order_start_time = (TextView) convertView.findViewById(R.id.order_start_time_value);
			holder.order_end_time = (TextView) convertView.findViewById(R.id.order_end_time_value);
			convertView.setTag(holder);
		}else {
			holder = (ViewHolder) convertView.getTag();
		}
		holder.num.setText((position+1)+"");
		if(!TextUtils.isEmpty(beans.get(position).ordernum)){
			holder.num.setText(beans.get(position).ordernum);
		}
		if(!TextUtils.isEmpty(beans.get(position).nickname)){
			holder.nick.setText(AppConstant.URLDecoderString(beans.get(position).nickname));
		}
		if(!TextUtils.isEmpty(beans.get(position).carnumber)){
			holder.car_num.setText(AppConstant.URLDecoderString(beans.get(position).carnumber));
		}
		if(!TextUtils.isEmpty(beans.get(position).addtime)){
			holder.addtime.setText(TimeUtils.parseLongToDate(beans.get(position).addtime, "yyyy-MM-dd HH:mm"));
		}
		if(!TextUtils.isEmpty(beans.get(position).orderstarttime)){
			holder.order_start_time.setText(TimeUtils.parseLongToDate(beans.get(position).orderstarttime, "yyyy-MM-dd HH:mm"));
		}
		if(!TextUtils.isEmpty(beans.get(position).orderendtime)){
			holder.order_end_time.setText(TimeUtils.parseLongToDate(beans.get(position).orderendtime, "yyyy-MM-dd HH:mm"));
		}
		//TODO 做一些赋值操作。
//		holder.nick.setText(AppConstant.URLDecoderString(beans.get(position).nick));
//		holder.car_num.setText(AppConstant.URLDecoderString(beans.get(position).nick));
//		holder.date.setText(AppConstant.URLDecoderString(beans.get(position).date));
		return convertView;

	}

	class ViewHolder {
		TextView num;//表示排序的编号
		TextView addtime;//日期
		TextView nick;//昵称
		TextView car_num;//车牌号
		TextView order_start_time;
		TextView order_end_time;
	}


}
